/**
 * 去掉字符串头尾空格
 * <p><b>Example: </b><p>
 * <p>trim(" Minim ") returns "Minim"<p>
 * @param strValue 字符串表达式
 * @return 头尾无空格的字符串表达式
 */
function trim(s)
{
  var strReturn;
  strReturn=s;

  while(strReturn.indexOf(" ")==0) strReturn=strReturn.substring(1);
  if(strReturn.length==0) return "";
  while(strReturn.lastIndexOf(" ")==strReturn.length-1)
  {
	strReturn=strReturn.substring(0,strReturn.length-1);
	if(strReturn.length==0) return "";
  }
  return strReturn;
}


/**
 * 分页链接函数
 * @param page 访问页数
 * @return 提交查询
 */
function onJump(url,page){
	var pagerForm=document.getElementById("pagerForm");
   	if(page==''||page==null){
     	 pagerForm.action=url;
   	}else{
   		//判断是否有参数
   		if(url.indexOf("?")>-1) {
   			pagerForm.action=url+"&startPage="+page;
   		} else {
   			pagerForm.action=url+"?startPage="+page;
   		}   	  
   	}
	pagerForm.submit();
}


/**
 * 全选复选框
 * @return true/false
 */
function changeAll(checkboxflag) {	
	var checkboxs=document.getElementsByName("boxIds"); 
	if (!checkboxflag) {
		for ( var i = 0; i < checkboxs.length; i++) {
			checkboxs[i].checked = false;
		}
	} else {
		for ( var i = 0; i < checkboxs.length; i++) {
			checkboxs[i].checked = true;
		}
	}
}

/**
 * 增加
 * @return true/false
 */
function add(url){
	window.location.href=url; 
}	

/**
 * 修改
 * @return true/false
 */
function up(url){
	var checkboxs=document.getElementsByName("boxIds");
	var j=0;
	var falg = false;
	var arr=null;
    for(var i=0;i<checkboxs.length;i++){
        if(checkboxs[i].checked){
      	    j+=1;
      	    arr=checkboxs[i].value;
        }
    }
    if(j!=1){
    	alert("请选择一条信息进行操作!");
    	return false;
    }else{
    	 //判断是否有参数
         if(url.indexOf("?")>-1) {
        	 window.location.href=url+"&arr="+arr;
         } else {
        	 window.location.href=url+"?arr="+arr;
         }   
         falg = true;
    }
}

/**
 * 删除
 * @return
 */
function del(url){
	var checkboxs=document.getElementsByName("boxIds"); 
	var falg = false;
	for(var i=0;i<checkboxs.length;i++){
	    if(checkboxs[i].checked){
	        falg = true;
	    }
	}
	if(!falg){
		alert("删除不能为空!");       
		return false;
	}else{      
		if(confirm("确定删除吗?")){
			delId="";
			for(var i=0;i<checkboxs.length;i++){
				if(checkboxs[i].checked){
					delId+=checkboxs[i].value+"|";
				}
			}
			//判断是否有参数
			if(url.indexOf("?")>-1) {
				window.location.href = url+ "&arr="+delId+"&startPage=&radom="+Math.random();
			} else {
				window.location.href = url+ "?arr="+delId+"&startPage=&radom="+Math.random();
			}   
		}
	}
}

/**
 * 根据id删除一条信息的操作
 * 同时可以用在别的需要确认的操作中
 * @param url	处理请求的url
 * @param id	需要操作的id
 * @param msg	弹出的msg
 * @returns {Boolean}
 */
function delOne(url, id, msg) {
	if(trim(id) != "") {
		if(confirm(msg)){
			//判断是否有参数
			if(url.indexOf("?")>-1) {
				window.location.href = url+ "&arr="+id+"&startPage=&radom="+Math.random();
			} else {
				window.location.href = url+ "?arr="+id+"&startPage=&radom="+Math.random();
			}
		}
	} else {
		alert("操作不能为空!");       
		return false;
	}
}

/**
 * 选择提交（无参数）
 * @return
 */
function chooseSubmit(url){
	var checkboxs=document.getElementsByName("boxIds"); 	
	var falg = false;
	for(var i=0;i<checkboxs.length;i++){
	    if(checkboxs[i].checked){
	        falg = true;
	    }
	}
	if(!falg){
		alert("选择不能为空!");       
		return false;
	}else{ 
		delId="";
		for(var i=0;i<checkboxs.length;i++){
			if(checkboxs[i].checked){
				delId+=checkboxs[i].value+"|";
			}
		}
		//判断是否有参数
		if(url.indexOf("?")>-1) {
			fm.action=url+ "&arr="+delId+"&radom="+Math.random();	 
		} else {
			fm.action=url+ "?arr="+delId+"&radom="+Math.random();	 
		}   
		fm.submit();
	}
}


/**
 * 设置提交按钮不可以提交
 * @return
 */
function setBufftonDisabled(flag) {  
    var sameSubmit = document.getElementById("sameSubmit"); 
    sameSubmit.disabled = flag;  
}  



/**
 * 添加收藏
 * @return
 */
var collect_page = function (obj, url, title) {
    var e = window.event || arguments.callee.caller.arguments[0];
    var B = {
        IE : /MSIE/.test(window.navigator.userAgent) && !window.opera
        , FF : /Firefox/.test(window.navigator.userAgent)
        , OP : !!window.opera
    };
    obj.onmousedown = null;	
    if (B.IE) {
        obj.attachEvent("onmouseup", function () {
            try {
                window.external.AddFavorite(url, title);
                window.event.returnValue = false;
            } catch (exp) {}
        });
    } else {	    	
        if (B.FF || obj.nodeName.toLowerCase() == "a") {
            obj.setAttribute("rel", "sidebar"), obj.title = title, obj.href = url;
        } else if (B.OP) {
            var a = document.createElement("a");
            a.rel = "sidebar", a.title = title, a.href = url;
            obj.parentNode.insertBefore(a, obj);
            a.appendChild(obj);
            a = null;
        }
    }
};


/**
 * 打开不重复的新窗口
 * @return
 */
function openNewPage(url,width,height,objName){	  
    var x = window.screen.height;
    var y = window.screen.width;
    var model = "title=word,resizable=yes,scrollbars=yes,height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,top=" + (x-height)/2 + ",left=" + (y-width)/2;
    var oOpen = window.open(url, objName, model);
    oOpen.focus();
}


